package com.xyy.saas.payment.payment.core.service;

import com.xyy.saas.payment.dao.model.ChannelSwitchInfo;
import com.xyy.saas.payment.dao.model.PayAccount;
import com.xyy.saas.payment.service.ChannelSwitchInfoService;
import com.xyy.saas.payment.service.PayAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;

@Slf4j
@Service
public class ChannelSwitchService {
    @Resource
    private ChannelSwitchInfoService channelSwitchInfoService;
    @Resource
    private PayAccountService payAccountService;

    /**
     * 判断商户是否在白名单
     * @param accountId
     * @return
     */
    public boolean exits(String accountId) {
        try {
            PayAccount payAccount = payAccountService.getPayAccountByAccountId(accountId);
            ChannelSwitchInfo param = new ChannelSwitchInfo();
            param.setBusinessIdType(payAccount.getBusinessIdType());
            param.setBusinessId(payAccount.getBusinessUserId());
            return !CollectionUtils.isEmpty(channelSwitchInfoService.queryByParam(param));
        }
        catch(Exception ex) {
            log.error(ex.getMessage() + ", accountId=" + accountId,ex);
        }

        return false;
    }
}
